package com.ruoyi.store.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.store.domain.TStore;
import com.ruoyi.store.service.ITStoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 店铺管理Controller
 *
 * @author 陈捷
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/business/manager")
public class TStoreController extends BaseController
{
    @Autowired
    private ITStoreService tStoreService;

    /**
     * 查询店铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:manager:list')")
    @GetMapping("/list")
    public TableDataInfo list(TStore tStore)
    {
        startPage();
        List<TStore> list = tStoreService.selectTStoreList(tStore);
        return getDataTable(list);
    }

    /**
     * 导出店铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:manager:export')")
    @Log(title = "店铺管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TStore tStore)
    {
        List<TStore> list = tStoreService.selectTStoreList(tStore);
        ExcelUtil<TStore> util = new ExcelUtil<TStore>(TStore.class);
        util.exportExcel(response, list, "店铺管理数据");
    }

    /**
     * 获取店铺管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:manager:query')")
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") String storeId)
    {
        return success(tStoreService.selectTStoreByStoreId(storeId));
    }

    /**
     * 新增店铺管理
     */
    @PreAuthorize("@ss.hasPermi('business:manager:add')")
    @Log(title = "店铺管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TStore tStore)
    {
        return toAjax(tStoreService.insertTStore(tStore));
    }

    /**
     * 修改店铺管理
     */
    @PreAuthorize("@ss.hasPermi('business:manager:edit')")
    @Log(title = "店铺管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TStore tStore)
    {
        return toAjax(tStoreService.updateTStore(tStore));
    }

    /**
     * 删除店铺管理
     */
    @PreAuthorize("@ss.hasPermi('business:manager:remove')")
    @Log(title = "店铺管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable String[] storeIds)
    {
        return toAjax(tStoreService.deleteTStoreByStoreIds(storeIds));
    }

    @GetMapping("/getStoreByUser")
    public TStore getStoreByUser(@RequestParam("userId")Long userId){
        return tStoreService.selectStoreByUserId(userId);
    }

}
